package com.sctvcloud.dongqu.http;

import android.support.annotation.NonNull;
import android.text.TextUtils;

import com.google.gson.Gson;

import java.lang.reflect.Type;
import java.util.List;

/**
 * Created by liuyu on 2017/10/27.
 */

public abstract class AbsStringListNetCallback<T> extends AbsNetCallBack<String> {

    protected List<T> gettedList;

    public AbsStringListNetCallback(Type type) {
        super(type);
    }

    public AbsStringListNetCallback(Type type, int i1) {
        super(type);
        this.int1 = i1;
    }

    public AbsStringListNetCallback(Type type, int i1, int i2) {
        super(type);
        this.int1 = i1;
        this.int2 = i2;
    }

    public AbsStringListNetCallback(Type type, Object o) {
        super(type);
        this.obj = o;
    }

    @Override
    public final void onSuc(String s) {
        onSuced(gettedList);
    }

    @Override
    public String doInBackground(String s) {
        if (!TextUtils.isEmpty(s)) {
            parseString(s);
        }
        return super.doInBackground(s);
    }

    @NonNull
    public Gson getGsons() {
        return new Gson();
    }

    public abstract void onSuced(List<T> ts);

    protected void parseString(String s) {
        if (type != null) {
            Gson gson = getGsons();
//            gettedList = GsonUtil.parseJsonWithGson(s, type);
            gettedList = gson.fromJson(s, type);
        }
    }
}
